package com.sc.controller.rui;

import com.sc.domain.Storage;
import com.sc.dto.StorageDto;
import com.sc.result.Result;
import com.sc.service.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:
 * @Author: Rui
 * @Date: 2024/11/27 13:42
 */
//储物室模块
@CrossOrigin
@RestController
@RequestMapping("storage")
public class StorageController {
    @Autowired
    private StorageService storageService;

//    新建储物室
    @PostMapping("addStorage")
    public Result addStorage(@RequestBody Storage storage){
        return Result.success("添加成功",storageService.addStorage(storage));
    }
//    删除储物室
    @DeleteMapping("deleteStorage/{id}")
    public Result deleteStorageById(@PathVariable Long id){
        return Result.success("删除成功",storageService.deleteStorageById(id));
    }
//    编辑储物室
    @PutMapping("updateStorage")
    public Result updateStorage(@RequestBody Storage storage){
        return Result.success("修改成功",storageService.updateStorage(storage));
    }
//    回显整个储物室列表以及模糊查询和 编辑时候查询
    @PostMapping("pageQuery")
    public Result pageQuery(@RequestBody StorageDto storageDTO ){
        return Result.success("查询成功",storageService.pageQuery(storageDTO));
    }
//    编辑时候的数据回显
    @GetMapping("selectById")
    public Result selectById(Long id){
        return Result.success("查询成功",storageService.selectById(id));
    }


//    批量删除
    @DeleteMapping("deleteStorageByIds")
    public Result deleteStorageByIds(@RequestBody List<Integer> ids){
        return Result.success("删除成功",storageService.deleteStorageByIds(ids));
    }
}
